<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="公厕名称" prop="toiletName">
        <el-input v-model="queryParams.toiletName" width="300" :disabled="true" placeholder="请输入公厕名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="月份">
        <el-date-picker v-model="queryParams.createDate" type="month" placeholder="选择月" />
      </el-form-item> -->

      <!-- <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item> -->
    </el-form>
    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExportMonthly"
          v-hasPermi="['toiletv2:toiletV2:export']">导出月报</el-button>
      </el-col>
    </el-row>

    <el-table :data="dataList.list" height="720" border>
      <el-table-column align="center" label="序号" type="index" width="50"></el-table-column>
      <el-table-column align="center" label="检查内容" prop="date" width="110">
        <template slot-scope="scope">
          <div>
            {{ getContent(scope.row.key) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="异常（个）" prop="daye" sortable width="160">
        <template slot-scope="scope">
          <div>{{ getYc(scope.row.key) }}</div>
        </template>
      </el-table-column>
      <el-table-column v-for="item in dataList.days" :key="item" align="center" :label="item + '日'" prop="date"
        width="60">
        <template slot-scope="scope">
          <div v-if="scope.row.value['d' + item]">
            <TickCross :value="scope.row.value['d' + item]" />
          </div>
        </template>
      </el-table-column>
    </el-table>



    <!-- 添加或修改V2市政公厕管养对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getToiletMonthly, selectCondition } from "@/api/v2Toilet/toilet";
import TickCross from "@/views/components/tickCross";

export default {
  name: "ToiletV2-Monthly",
  dicts: ['inspection_status', 'sys_common_status'],
  components: {
    TickCross
  },
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // V2市政公厕管养表格数据
      dataList: {},
      // 弹出层标题
      title: "",
      // 是否新增
      isAdd: true,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        toiletName: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    const toiletName = this.$route.query && this.$route.query.toiletName;
    this.queryParams.toiletName = toiletName;
    this.getList();
    this.$store.dispatch('tagsView/updateVisitedView', {path: '/toiletv2/monthly',meta:{title:toiletName+ " 月报"}})

  },
  methods: {
    cellClick(row, column, cell, event) {
      // alert("待实现")
      //后台获取 需要弹框的列表，判断 column.property 是否在弹框里；是 带ID和column.property 去查询
      // console.log(column.property, "------->", column)
    },
    selectItemsEvent() {
      //公厕下拉
      selectCondition().then(resp => {

        // console.log(resp)
      });
    },
    /** 查询V2市政公厕管养列表 */
    getList(toiletName, createDate) {
      this.loading = true;
      // getToiletMonthly(toiletName, createDate).then(response => {
      getToiletMonthly(this.queryParams).then(response => {
        this.dataList = response.data;
        delete this.dataList.list.anomalyProcessCount;
        delete this.dataList.list.anomalyCount;
        delete this.dataList.list.cleanCount;
        this.dataList.list = Object.keys(this.dataList.list).map(val => ({
          key: val,
          value: this.dataList.list[val]
        }))
        this.loading = false;
      });
    },
    getContent(val) {
      return this.dataList.columns[val]
    },
    getYc(val) {
      return this.dataList.rc[val]
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // this.getList();
      console.log(this.parseTime(this.queryParams.createDate, '{y}{m}{d}'))
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


    /** 导出按钮操作 */
    // handleExport() {
    handleExportMonthly() {
      this.download('toiletv2/toiletV2/exportMonth', {
        ...this.queryParams
      }, `${this.queryParams.toiletName}月报${this.parseTime(new Date(), '{y}{m}{d}')}.xlsx`)

    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
.el-table .cell {
  padding: 0;
}

.el-table--medium .el-table__cell {
  padding: 0;
}
</style>
